package com.sjlh.centurylianhua.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sjlh.centurylianhua.dto.SearchCon;
import com.sjlh.centurylianhua.entity.Company;
import com.sjlh.centurylianhua.mapper.CompanyMapper;
import com.sjlh.centurylianhua.utils.ResultData;
import com.sjlh.centurylianhua.utils.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/company")
public class CompanyController {

    @Resource
    private CompanyMapper companyMapper;

    /**
     * 精确查询
     */
    @RequestMapping("/getAll")
    public Object getAll(@RequestBody SearchCon searchCon){
        QueryWrapper<Company> wrapper = new QueryWrapper<>();
        wrapper.like(StringUtils.isnotNull(searchCon.getName()), "companyName", searchCon.getName());
        // 封装分页对象
        Page<Company> page = new Page<Company>(searchCon.getPage(), searchCon.getLimit());
        Page<Company> userPage = companyMapper.selectPage(page, wrapper);
        List<Company> list=userPage.getRecords();//所有数据
        long count=userPage.getTotal();//总条数
        ResultData rs=new ResultData(true,20000,"成功",list,count);
        return rs;
    }
}
